package com.lc.dao.impl;

import com.lc.dao.DBUtils;
import com.lc.dao.MiddleDao;

import java.sql.PreparedStatement;

/**
 * @description:
 * @author: ManolinCoder
 * @time: 2021/8/25
 */
public class MiddleDaoImpl extends DBUtils implements MiddleDao {
    //在中间表中新增角色
    @Override
    public int insertMiddle(int roleid, String[] ids) {
        int i = 0;
        String sql = "insert into middle values(null,?,?)";
        //批量新增
        try {
            pps = getPps(sql);
            for (String id : ids) {
                pps.setInt(1,roleid);
                pps.setString(2,id);
                pps.addBatch();
            }
            pps.executeBatch();
            i = 1;//执行成功返回1
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            closeAll();
        }
        return i;
    }
}
